﻿using Model;
using Models;
using Newtonsoft.Json.Linq;
using PublicMethod;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace OrderingOnlineWeChat.Controllers
{
    public class FormController : BaseControl
    {
        #region 声明
        ZHHQService.Service1Client server1 = new ZHHQService.Service1Client();
        DCXTService.Service1Client server2 = new DCXTService.Service1Client();
        #endregion
        //
        // GET: /Form/
        #region 根据订单ID获取订单信息
        /// <summary>
        /// 根据订单ID获取订单信息
        /// </summary>
        /// <param name="orderNum"></param>
        /// <returns></returns>
        #endregion
        public ActionResult Index()
        {
            return View();
         
        }

        public ActionResult Formby(string FormID)
        {
            try
            {
                string result = server2.GetOrder_FormLog(Convert.ToInt32(FormID), GetYZM._YZM, 1);
                JObject jb = JObject.Parse(result);
                List<Model.FormInfo> list = new List<FormInfo>();
                StringBuilder sb = new StringBuilder();
                if (jb["BS"].ToString() == "1")
                {
                    IList<JToken> jt = jb["rows"].Children().ToList();
                    list = ParseClass<Model.FormInfo>.JsonList(jt);
                    int i = 0;
                    string[] isStarOrBook = new string[2] { "book", "star" };
                    string[] rightOrLeft = new string[2] { "timeline-content", "timeline-content right" };
                    foreach (var item in list)
                    {
                        item.OperaType = i % 2;
                        // sb.Append("<div class=\"timeline-item\"><div class=\"timeline-icon\"><img src=\"/Content/zhuangtai/images/" + isStarOrBook[i % 2] + ".svg\" alt=\"\"></div><div class=\"" + rightOrLeft[i % 2] + "\">");
                        i++;
                        item.LogTime = item.LogTime.PadRight(14, '0');
                        item.PreTime = item.PreTime.PadRight(14, '0');
                        if (!string.IsNullOrWhiteSpace(item.LogTime))
                        {
                            string mon = item.LogTime.Substring(4, 2);
                            mon = (mon.Substring(0, 1)) == "1" ? mon.Substring(1, 1) : mon;
                            string date = item.LogTime.Substring(6, 2);
                            string hour = item.LogTime.Substring(8, 2);
                            string min = item.LogTime.Substring(10, 2);
                            item.LogTime = mon + "月" + date + "日 " + hour + "：" + min;
                            //sb.Append("<h2>" + mon + "月" + date + "日" + hour + "：" + min + "</h2>");
                        }
                        //sb.Append("<p>");
                        //if (!string.IsNullOrWhiteSpace(item.ConText))
                        //{
                        //    sb.Append("<p>" + item.ConText + "</p>");
                        //}
                        //sb.Append("<p>" + item.Tip + "：" + item.Name + "</p><p>联系方式：" + item.Call + "</p>");
                        if (!string.IsNullOrWhiteSpace(item.PreTime))
                        {
                            item.PreTime = item.PreTime.Substring(0, 4) + "-" + item.PreTime.Substring(4, 2) + "-" + item.PreTime.Substring(6, 2) + " " + item.PreTime.Substring(8, 2) + ":" + item.PreTime.Substring(10, 2) + ":" + item.PreTime.Substring(12, 2);
                            //sb.Append("<p>预计完成时间：" + item.PreTime.Substring(0, 4) + "-" + item.PreTime.Substring(4, 2) + "-" + item.PreTime.Substring(6, 2) + " " + item.PreTime.Substring(8, 2) + ":" + item.PreTime.Substring(10, 2) + ":" + item.PreTime.Substring(12, 2) + "</p>");
                        }
                        //sb.Append("</p></div></div>");
                    }
                }


                //string result = server2.ReBookOrder(FormID, PayID, lx, GetYZM._YZM, 1);

                //JObject jb = JObject.Parse(result);

                var json = new
                {
                    bs = jb["BS"].ToString(),
                    data = list,
                    mes = jb["Msg"].ToString(),
                };
                //return Json(json);
                return Json(json, JsonRequestBehavior.AllowGet);
                // ViewBag.ztl = sb.ToString();
            }
            catch (Exception ex)
            {
                var json = new
                {
                    bs = "-99",
                    mes ="查询失败，系统异常：#3",
                };
                return Json(json, JsonRequestBehavior.AllowGet);
            }
        
        }
        //public class FormInfo
        //{
        //    public int OperaType { get; set; }
        //    public string ConText { get; set; }
        //    public string Tip { get; set; }
        //    public string Name { get; set; }
        //    public string Call { get; set; }
        //    public string PreTime { get; set; }

        //    public string LogTime { get; set; }
        //}
            public class Send_Form
            {
                //public int FormID { get; set; }//订单id
                //public string FormTime { get; set; }//下单时间
                //public string FormBY { get; set; }//订单状态
                //public string LastTime { get; set; }// 最后修改时间
                //public string AccCall { get; set; }//用户电话
                //public string MerID { get; set; }// 商户id
                //public string MerName { get; set; }//商户名
                //public string TakerName { get; set; }//派送员姓名
                //public string TakerOpenID { get; set; }//id
                //public string TakerPhone { get; set; }//电话
                public int LastUser { get; set; }
                public string LastTime { get; set; }
                public string BZ { get; set; }
                public int SendState { get; set; }
                public string TakerName { get; set; }
                public string TakerPhone { get; set; }
                public string TakerOpenID { get; set; }

                public string ConText { get; set; }
                public int ConIsOut { get; set; }
                public string NextCon { get; set; }
                public string ConID { get; set; }
                public int TakerID { get; set; }
                public int FormID { get; set; }
                public string SenTime { get; set; }

                public string FormTime { get; set; }//下单时间
                public string FormBY { get; set; }//订单状态
                public string FormAddress { get; set; }
                public string AccName { get; set; }
                public int AccID { get; set; }
                public string AccCall { get; set; }

                public string MerID { get; set; }
                public string MerName { get; set; }
                public string MerCall { get; set; }
            }
        
        
    }
}
